package sk.gtug.pivoplus.malepivo;

import sk.gtug.pivoplus.malepivo.utils.GeoUtils;
import sk.gtug.pivoplus.server.domain.twig.TwigKrcmicka;
import android.location.Location;

/**
 * Class represents a pub.
 * @author biegleux
 *
 */
public class PubItem extends TwigKrcmicka implements Comparable<PubItem> {

	private double mDirection = 0;
	// TODO, tie co nemaju definovany distance, nech su na konci, preto MAX
	private float mDistance = Float.MAX_VALUE;// 0.0f;

	/**
	 * Sets the direction from the specified location.
	 * @param location
	 */
	public void setDirection(Location location) {
		if (hasCoords()) {
			mDirection = GeoUtils.bearing(location.getLatitude(),
					location.getLongitude(), getLatitude(), getLongitude());
		}
	}

	public double getDirection() {
		return mDirection;
	}

	/**
	 * Sets the distance from the specified location.
	 * @param location
	 */
	public void setDistance(Location location) {
		if (hasCoords()) {
			float results[] = new float[1];
			Location.distanceBetween(location.getLatitude(), location.getLongitude(),
					getLatitude(), getLongitude(), results);
			mDistance = results[0];
		}
	}

	public float getDistance() {
		return mDistance;
	}

	public boolean hasCoords() {
		return getLatitude() != null && getLongitude() != null;
	}

	public int compareTo(PubItem pubItem) {
		if (getDistance() > pubItem.getDistance()) {
			return 1;
		} else if (getDistance() < pubItem.getDistance()) {
			return -1;
		} else {
			return 0;
		}
	}
}
